package books.borrowing.bo.impl;

import java.util.GregorianCalendar;
import java.util.List;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.ws.WebServiceRef;

import org.springframework.stereotype.Component;

import books.borrowing.bo.IBookManagerClientService;
import books.storage.service.BookDto;
import books.storage.service.BooksManagerBean;
import books.storage.service.BooksManagerBeanService;
import books.storage.service.EntityNotFoundException_Exception;
import books.storage.service.LiteraryGenreDto;
import books.storage.service.NotEnoughtExemplaireException_Exception;

@Component
public class BookManagerClientServiceImpl implements IBookManagerClientService {

    @WebServiceRef(wsdlLocation = "http://localhost:8080/BooksManagerBeanService/BooksManagerBean?wsdl", value = BooksManagerBeanService.class)
    //Interface generated by wsimport
    private BooksManagerBean _bean;

    /**
     * SEARCH
     * @throws DatatypeConfigurationException 
     */
    
    public List<BookDto> search(GregorianCalendar _first, GregorianCalendar _end) throws DatatypeConfigurationException {
		XMLGregorianCalendar xmlCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(_first);
		XMLGregorianCalendar xmlCalendar2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(_end);
    	return _bean.searchBookBetweenEditionDates(xmlCalendar, xmlCalendar2);
    }
    
    public List<BookDto> searchBookByAuthor(String _authorName) {
    	return _bean.searchBookByAuthor(_authorName);
    }
    
    public List<BookDto> searchBookByGenre(String _genreName) {
    	return _bean.searchBookByLiteraryGenre(_genreName);
    }
    
    public List<BookDto> searchBookByTitle(String _title) {
    	return _bean.searchBookByName(_title);
    }
    
    /**
     * BOOKS
     */
    
    public BookDto addNewBook(BookDto _book) throws EntityNotFoundException_Exception {
    	return _bean.addNewBook(_book);
    }
    
    public BookDto findBook(String _ISBN) throws EntityNotFoundException_Exception {
		return _bean.findBookDto(_ISBN);
	}
    
    public BookDto updateBook(BookDto _book) throws EntityNotFoundException_Exception {
    	return _bean.updateBook(_book);
    }
    
    public void removeBook(BookDto _book) throws EntityNotFoundException_Exception {
    	_bean.deleteBook(_book);
    }
    
    public BookDto removeCopies(int _nb, BookDto _book) throws EntityNotFoundException_Exception, NotEnoughtExemplaireException_Exception {
    	return _bean.removeCopies(_nb, _book);
    }
    
    public BookDto addCopies(int _nb, BookDto _book) throws EntityNotFoundException_Exception {
    	return _bean.addCopies(_nb, _book);
    }
    
    public List<BookDto> findAllBooks() {
    	return _bean.findAllBooks();
    }
    
    /**
     * LITERARY GENRE
     */
    
    public LiteraryGenreDto addNewLiteraryGenreDto(LiteraryGenreDto _genre) throws EntityNotFoundException_Exception {
    	return _bean.addNewLiteraryGenre(_genre);
    }
    
    public LiteraryGenreDto findLiteraryGenreDto(Integer _id) throws EntityNotFoundException_Exception {
    	return _bean.findLiteraryGenreDto(_id);
    }
    
    public LiteraryGenreDto updateLiteraryGenre(LiteraryGenreDto _genre) throws EntityNotFoundException_Exception {
    	return _bean.updateLiteraryGenre(_genre);
    }
    
    public void removeLiteraryGenre(LiteraryGenreDto _genre) throws EntityNotFoundException_Exception {
    	_bean.deleteLiteraryGenre(_genre);
    }
    
    public List<LiteraryGenreDto> findAllLiteraryGenre() {
    	return _bean.findAllGenre();
    }
}
